home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-03 | 102.9 KB | 3,527 lines | [TEXT/MPS ] |
- //----------------------------------------------------------------------------------------
- // UDialog.cp
- // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
- //----------------------------------------------------------------------------------------
-
- #ifndef __UDIALOG__
- #include "UDialog.h"
- #endif
-
- // MacApp
-
- #ifndef __MACAPPTYPES__
- #include "MacAppTypes.h"
- #endif
-
- #ifndef __UADORNERS__
- #include "UAdorners.h"
- #endif
-
- // #ifndef __UAPPLICATION__
- // #include "UApplication.h"
- // #endif
-
- #ifndef __UASSOCIATION__
- #include "UAssociation.h"
- #endif
-
- #ifndef __UDIALOGBEHAVIOR__
- #include "UDialogBehavior.h"
- #endif
-
- #ifndef __UDISPATCHER__
- #include "UDispatcher.h"
- #endif
-
- #if qDrag
- #ifndef __UDRAGDROP__
- #include "UDragDrop.h"
- #endif
- #endif
-
- #ifndef __UERRORMGR__
- #include "UErrorMgr.h"
- #endif
-
- #ifndef __UGEOMETRY__
- #include "UGeometry.h"
- #endif
-
- #ifndef __UITERATOR__
- #include "UIterator.h"
- #endif
-
- #ifndef __UMACAPPGLOBALS__
- #include "UMacAppGlobals.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UMEMORY__
- #include "UMemory.h"
- #endif
-
- #ifndef __UPOPUP__
- #include "UPopup.h"
- #endif
-
- #ifndef __USCROLLER__
- #include "UScroller.h"
- #endif
-
- #ifndef __USTREAM__
- #include "UStream.h"
- #endif
-
- #ifndef __USUBSTITUTION__
- #include "USubstitution.h"
- #endif
-
- #ifndef __UTECOMMANDS__
- #include "UTECommands.h"
- #endif
-
- #ifndef __UVIEWSERVER__
- #include "UViewServer.h"
- #endif
-
- #ifndef __UWINDOW__
- #include "UWindow.h"
- #endif
-
- // Toolbox
-
- #ifndef __FP__
- #include <fp.h>
- #endif
-
- #ifndef __ICONS__
- #include <Icons.h>
- #endif
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __STRINGS__
- #include <Strings.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- // ANSI
-
- #ifndef __LIMITS__
- #include <limits.h>
- #endif
-
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- #if qModelCFM
- #ifndef __STDLIB__
- #include <stdlib.h>
- #endif
- #endif
-
- //----------------------------------------------------------------------------------------
-
- // TAssociation* gParamTxt; // Used for text substitution
-
- TFloatingTEManager* gFloatingTEManager; // The floating TEView used with edit text
- // fields.
-
-
- //========================================================================================
- // GLOBAL Procedures
- //========================================================================================
- #undef Inherited
-
- //----------------------------------------------------------------------------------------
- // InitUDialog:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- void InitUDialog()
- {
- if (gUDialogInitialized)
- return;
-
- if (qTemplateViews)
- {
- // So the linker doesn't dead strip these
- MA_REGISTER_SIGNATURE(TDialogView, kStdDialogView);
- MA_REGISTER_SIGNATURE(TControl, kStdControl);
- MA_REGISTER_SIGNATURE(TButton, kStdButton);
- MA_REGISTER_SIGNATURE(TCheckBox, kStdCheckBox);
- MA_REGISTER_SIGNATURE(TRadio, kStdRadio);
- MA_REGISTER_SIGNATURE(TCluster, kStdCluster);
- MA_REGISTER_SIGNATURE(TIcon, kStdIcon);
- MA_REGISTER_SIGNATURE(TIconSuite, kStdIconSuite);
- MA_REGISTER_SIGNATURE(TSmallIcon, kStdSmallIcon);
- MA_REGISTER_SIGNATURE(TPicture, kStdPicture);
- MA_REGISTER_SIGNATURE(TPopup, kStdPopup);
- MA_REGISTER_SIGNATURE(TStaticText, kStdStaticText);
- MA_REGISTER_SIGNATURE(TEditText, kStdEditText);
- MA_REGISTER_SIGNATURE(TNumberText, kStdNumberText);
- MA_REGISTER_SIGNATURE(TPattern, kStdPattern);
- MA_REGISTER_SIGNATURE(TTargetBorderView, kStdTargetBorderView);
- MA_REGISTER_SIGNATURE(TDialogTEView, kStdDialogTEView);
- MA_REGISTER_SIGNATURE(TDialogBehavior, kStdDialogBehavior);
- }
-
- gFloatingTEManager = new TFloatingTEManager;
- gFloatingTEManager->IFloatingTEManager();
-
- // gParamTxt = new TAssociation;
- // gParamTxt->IAssociation();
- InitUSubstitution();
-
- gUDialogInitialized = TRUE;
- } // InitUDialog
-
-
- //----------------------------------------------------------------------------------------
- // AcquireFloatingTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- TDialogTEView* AcquireFloatingTEView()
- {
- if (gFloatingTEManager)
- return (gFloatingTEManager->AcquireFloatingTE());
- else
- return NULL;
- } // AcquireFloatingTEView
-
- //----------------------------------------------------------------------------------------
- // ReleaseFloatingTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void ReleaseFloatingTEView(TDialogTEView* aDialogTEView)
- {
- if (gFloatingTEManager)
- gFloatingTEManager->ReleaseFloatingTE(aDialogTEView);
- } // ReleaseFloatingTEView
-
- //----------------------------------------------------------------------------------------
- // MAParamText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- // void MAParamText(const CStr255& keyStr,
- // const CStr255& valueStr)
- //
- // {
- // gParamTxt->InsertEntry(keyStr, valueStr);
- // } // MAParamText
-
- //----------------------------------------------------------------------------------------
- // MAReplaceText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- // void MAReplaceText(CStr255& theText)
- // {
- // CArrayIterator iter(gParamTxt->fEntries);
- //
- // for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
- // {
- // TEntry* anEntry = (TEntry*)gParamTxt->fEntries->At(i);
- // short index;
- //
- // while ((index = theText.Pos(**(anEntry->fKey))) != 0)
- // {
- // theText.Delete(index, (**(anEntry->fKey)).Length());
- // if (theText.Length() + (**(anEntry->fValue)).Length() < sizeof(CStr255))
- // theText.Insert(**(anEntry->fValue), index);
- // }
- // }
- // } // MAReplaceText
-
-
- //========================================================================================
- // CLASS TDialogView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TDialogView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDialogView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TDialogView::TDialogView()
- {
- fDefaultItem = kNoIdentifier;
- fCancelItem = kNoIdentifier;
- } // TDialogView::TDialogView
-
- //----------------------------------------------------------------------------------------
- // TDialogView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TDialogView::~TDialogView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TDialogView::IDialogView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TDialogView::IDialogView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- IDType itsDefItemID,
- IDType itsCancelItemID)
-
- {
- #if qDebug
- if (!gUDialogInitialized)
- {
- ProgramBreak("InitUDialog must be called before creating a Dialog View.");
- Failure(noErr, 0);
- }
- #endif
-
- this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- fDefaultItem = itsDefItemID;
- fCancelItem = itsCancelItemID;
-
- } // TDialogView::IDialogView
-
-
- //----------------------------------------------------------------------------------------
- // TDialogView::DoPostCreate:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TDialogView::DoPostCreate(TDocument *itsDocument) // Override
- {
- Inherited::DoPostCreate(itsDocument);
-
- TWindow* theWindow = this->GetWindow();
- if (theWindow)
- theWindow->SetDialogItems(fDefaultItem,fCancelItem);
-
- } // TDialogView::DoPostCreate
-
- //----------------------------------------------------------------------------------------
- // TDialogView::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TDialogView::GetStandardSignature() // Override
- {
- return kStdDialogView;
- } // TDialogView::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TDialogView::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TDialogView::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- #if qDebug
- if (!gUDialogInitialized)
- {
- ProgramBreak("InitUDialog must be called before creating a Dialog View.");
- Failure(noErr, 0);
- }
- #endif
-
- FailInfo fi;
- Try(fi)
- {
- fDefaultItem = aStream->ReadIDType();
- fCancelItem = aStream->ReadIDType();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- } // TDialogView::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TDialogView::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TDialogView::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteIDType(fDefaultItem);
- aStream->WriteIDType(fCancelItem);
- } // TDialogView::WriteFields
-
-
- //========================================================================================
- // CLASS TCluster
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TCluster, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TCluster constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TCluster::TCluster()
- {
- fDataHandle = NULL;
- fStrListID = kNoResource;
- fIndex = kEmptySTRIndex;
- fCurrentChoice = kNoIdentifier;
- fEventNumber = mClusterHit;
- } // TCluster::TCluster
-
-
- //----------------------------------------------------------------------------------------
- // TCluster::ICluster:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TCluster::ICluster(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID,
- short itsIndex)
-
-
- {
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- fStrListID = itsRsrcID;
- fIndex = itsIndex;
- if (fStrListID != kNoResource)
- {
- CStr255 aString;
-
- FailInfo fi;
- Try(fi)
- {
- GetIndString(aString, fStrListID, fIndex);
- FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
-
- this->SetLabel(aString, kDontRedraw);
- }
- this->SetEnable(FALSE); // Default is not to enable hit testing
- } // TCluster::ICluster
-
- //----------------------------------------------------------------------------------------
- // TCluster::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- TObject* TCluster::Clone() // Override
- {
- MAVolatileInit(TCluster*, aClonedCluster, (TCluster *)(Inherited::Clone()));
-
- // set initial values:
- aClonedCluster->fDataHandle = NULL;
-
- if (fDataHandle)
- {
- FailInfo fi;
- Try(fi)
- {
- CStr255 theLabel;
- this->GetLabel(theLabel);
- aClonedCluster->SetLabel(theLabel, kDontRedraw);
- fi.Success();
- }
- else // Recover
- {
- aClonedCluster->Free();
- fi.ReSignal();
- }
- }
-
- return aClonedCluster;
- } // TCluster::Clone
-
- //----------------------------------------------------------------------------------------
- // TCluster::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- TCluster::~TCluster()
- {
- this->ReleaseLabel();
- } // TCluster::Free
-
- //----------------------------------------------------------------------------------------
- // TCluster::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TCluster::GetStandardSignature() // Override
- {
- return kStdCluster;
- } // TCluster::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TCluster::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TCluster::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- CStr255 theLabel;
- fStrListID = aStream->ReadInteger();
- fIndex = aStream->ReadInteger();
- if (fStrListID != kNoResource) // retrieve the buttons's label from the resource
- GetIndString(theLabel, fStrListID, fIndex);
- this->SetLabel(theLabel, kDontRedraw);
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TCluster::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TCluster::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TCluster::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteInteger(fStrListID);
- aStream->WriteInteger(fIndex);
- } // TCluster::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TCluster::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TCluster::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event)// Override
- {
- // If we got this far, a radio's changed state. Only worry about it if it's our subview!
- if ((eventNumber == mRadioHit) && (((TView *)source)->fSuperView == this))
- {
- CSubViewIterator iter(this);
-
- for (TView* theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- // If the subview is a TRadio, and it's not the calling radio…
- if (theSubView != source)
- theSubView->HandleEvent(mTurnOff, this, NULL); // …set it off and redraw it
- fCurrentChoice = source->fIdentifier;
- }
-
- Inherited::DoEvent(eventNumber, source, event);
- } // TCluster::DoEvent
-
- //----------------------------------------------------------------------------------------
- // TCluster::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TCluster::Draw(const VRect& area) // Override
- {
- static const short labelOffset = 16; // offset of label from left edge of cluster
-
- if (fDataHandle)
- {
- PenNormal(); // Normalcy in most things
-
- CPoint itsPenSize;
- this->GetPenSize(itsPenSize);
- PenSize(itsPenSize.h, itsPenSize.v);
-
- short theFontHeight;
-
- CRGBColor oldColor;
- GetIfColor(oldColor); // Save the original pen color
- { // block for CWhileOutlinePreferred (which has a constructor/destructor)
- CWhileOutlinePreferred setOP(fPreferOutline);
-
- TextStyle aTextStyle = fTextStyle;
- FontInfo theFontInfo;
- GetTextStyleFontInfo(aTextStyle, theFontInfo, theFontHeight);
- }
- // retrieve the label and set it
- CStr255 theText;
- this->GetLabel(theText);
- MAReplaceText(theText);
- VRect labelRect(labelOffset, 0, labelOffset + StringWidth(theText) + 8, theFontHeight);
-
- CRect theQDFrame(this->ControlQDArea()); // Get the control's extent
- VCoordinate theFrameTop = theQDFrame.top + ((theFontHeight) >> 1);
-
- theQDFrame.Inset(itsPenSize + CPoint(1, 1)); // Inset the frame a little.
-
- theQDFrame.top = theFrameTop; // Bump top so it cuts label in half
-
- // Draw the frame. We can't use FrameRect here because top line appears behind
- // the text when printing regardless of whether we eraseRect first or not.
- MoveTo(theQDFrame.left + labelOffset, theQDFrame.top);
- LineToPt(theQDFrame[topLeft]);
- LineTo(theQDFrame.left, theQDFrame.bottom);
- LineToPt(theQDFrame[botRight]);
- LineTo(theQDFrame.right, theQDFrame.top);
- LineTo(theQDFrame.left + labelOffset + (short)labelRect.GetLength(hSel), theQDFrame.top);
-
- this->DrawLabel(area); // Draw the label
-
- SetIfColor(oldColor);
- }
- Inherited::Draw(area); // Let parents have a chance to draw too
- } // TCluster::Draw
-
- //----------------------------------------------------------------------------------------
- // TCluster::DrawLabel:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TCluster::DrawLabel(const VRect& area)
- {
- const short labelOffset = 16; // offset of label from left edge of cluster
-
- VRect labelRect;
-
- // retrieve the label and set it
- CStr255 theText;
- this->GetLabel(theText);
- MAReplaceText(theText);
-
- // Calculate the label's CRect
- { // block for CWhileOutlinePreferred (which has a constructor/destructor)
- CWhileOutlinePreferred setOP(fPreferOutline);
- FontInfo theFontInfo;
- labelRect = VRect(labelOffset, 0, labelOffset + StringWidth(theText) + 8, MAGetFontInfo(theFontInfo));
- }
-
- // Intersect label's CRect with the area. Draw label if valid intersection.
- if (!(labelRect & area).Empty())
- {
- Ptr textPtr = (Ptr)&theText; // get address of local CStr255 struct
- ++textPtr; // bump it to point to first byte in CString
- MATextBox(textPtr, theText.Length(), ViewToQDRect(labelRect), teCenter, kNoAutoWrap, NULL, kNoEraseFirst,
- kNoSpaceForCaret, fPreferOutline);
- }
- } // TCluster::DrawLabel
-
- //----------------------------------------------------------------------------------------
- // TCluster::GetLabel:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TCluster::GetLabel(CStr255& theLabel)
- {
- if (fDataHandle)
- theLabel = **((String255Handle)fDataHandle);
- else
- theLabel.Empty();
- } // TCluster::GetLabel
-
- //----------------------------------------------------------------------------------------
- // TCluster::ReleaseLabel:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TCluster::ReleaseLabel()
- {
- fDataHandle = (CStringHandle)DisposeIfHandle((Handle)fDataHandle);
- } // TCluster::ReleaseLabel
-
- //----------------------------------------------------------------------------------------
- // TCluster::SetLabel:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TCluster::SetLabel(const CStr255& theLabel,
- Boolean redraw)
-
- {
- this->ReleaseLabel();
- if (!theLabel.IsEmpty())
- {
- fDataHandle = (CStringHandle)NewString(theLabel);
- if (MemError() != noErr)
- fDataHandle = NULL;
- }
- if (redraw)
- this->ForceRedraw();
- } // TCluster::SetLabel
-
- //----------------------------------------------------------------------------------------
- // TCluster::SetLabelWithStrListID:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TCluster::SetLabelWithStrListID(ResNumber theStrListID, short theIndex, Boolean redraw)
- {
- this->ReleaseLabel();
-
- fStrListID = theStrListID;
- fIndex = theIndex;
- if (fStrListID != kNoResource)
- {
- CStr255 aString;
-
- GetIndString(aString, fStrListID, fIndex);
- FailResError();
- this->SetLabel(aString, kDontRedraw);
- }
-
- if (redraw)
- this->ForceRedraw();
- } // TCluster::SetLabelWithStrListID
-
- //----------------------------------------------------------------------------------------
- // TCluster::GetCurrentChoice:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- IDType TCluster::GetCurrentChoice()
- {
- return fCurrentChoice;
- } // TCluster::GetCurrentChoice
-
- //----------------------------------------------------------------------------------------
- // TCluster::SetCurrentChoice:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TCluster::SetCurrentChoice(IDType newChoice)
- {
- CSubViewIterator iter(this);
-
- for (TView* theSubView = iter.FirstSubView(); iter.More(); theSubView = iter.NextSubView())
- {
- if (theSubView->fIdentifier == newChoice)
- theSubView->DoEvent(mTurnOn, this, NULL);
- else
- theSubView->DoEvent(mTurnOff, this, NULL);
- }
- fCurrentChoice = newChoice;
- } // TCluster::SetCurrentChoice
-
-
- //========================================================================================
- // CLASS TPattern
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TPattern, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPattern constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TPattern::TPattern()
- {
- fDataHandle = NULL;
- fPreferColor = kPreferColor;
- fIsColor = kPreferColor;
- fRsrcID = kNoResource;
-
- fEventNumber = mPatternHit;
- } // TPattern::TPattern
-
- //----------------------------------------------------------------------------------------
- // TPattern::IPattern:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TPattern::IPattern(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID,
- Boolean preferColor)
- {
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fPreferColor = preferColor;
- fIsColor = preferColor;
-
- FailInfo fi;
- Try(fi)
- {
- this->SetPatternRsrcID(itsRsrcID, kDontRedraw);
-
- fi.Success();
- }
- else // Recover
- {
- this->Free();
-
- fi.ReSignal();
- }
-
- this->SetEnable(FALSE); // Default is to not enable hit testing
- } // TPattern::IPattern
-
- //----------------------------------------------------------------------------------------
- // TPattern::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- TObject* TPattern::Clone() // Override
- {
- MAVolatileInit(TPattern*, aClonedPattern, (TPattern *)(Inherited::Clone()));
-
- // don't call aClonedPattern->ReleasePattern() b/c this will free my memory
- // set initial values:
- aClonedPattern->fDataHandle = NULL;
- aClonedPattern->fPreferColor = kPreferColor;
- aClonedPattern->fIsColor = kPreferColor;
- aClonedPattern->fRsrcID = kNoResource;
-
- if (fDataHandle)
- {
- FailInfo fi;
- Try(fi)
- {
- aClonedPattern->SetPatternRsrcID(fRsrcID, kDontRedraw);
- fi.Success();
- }
- else // Recover
- {
- aClonedPattern->Free();
- fi.ReSignal();
- }
- }
-
- return aClonedPattern;
- } // TPattern::Clone
-
- //----------------------------------------------------------------------------------------
- // TPattern::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- TPattern::~TPattern()
- {
- this->ReleasePattern();
- } // TPattern::Free
-
- //----------------------------------------------------------------------------------------
- // TPattern::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TPattern::GetStandardSignature() // Override
- {
- return kStdPattern;
- } // TPattern::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TPattern::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TPattern::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- fPreferColor = aStream->ReadBoolean();
-
- fIsColor = fPreferColor;
-
- ResNumber itsRsrcID = aStream->ReadInteger();
- this->SetPatternRsrcID(itsRsrcID, kDontRedraw);
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- } // TPattern::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TPattern::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TPattern::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteBoolean(fPreferColor);
-
- #if qDebugMsg
- if (fRsrcID == kNoResource)
- fprintf(stderr, "Tried to write TPattern with no resource ID.\n");
- #endif
-
- aStream->WriteInteger(fRsrcID);
- } // TPattern::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TPattern::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TPattern::Draw(const VRect& area) // Override
- {
- if (fDataHandle)
- {
- if (IsAResource(fDataHandle) &&!fIsColor)// Pixpat handles != resource handles
- LoadResource(fDataHandle);
- if (*fDataHandle) // If there's room for the pattern…
- {
- PenNormal(); // NECESSARY?
- CRect theQDRect(this->ControlQDArea());
-
- SignedByte wasState = LockHandle(fDataHandle);
- if (fIsColor)
- FillCRect(theQDRect, (PixPatHandle)fDataHandle);
- else
- FillRect(theQDRect, *((PatHandle)fDataHandle));
- HSetState(fDataHandle, wasState);
- }
- }
-
- Inherited::Draw(area);
- } // TPattern::Draw
-
- //----------------------------------------------------------------------------------------
- // TPattern::ReleasePattern:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TPattern::ReleasePattern()
- {
- fRsrcID = kNoResource;
- if (fDataHandle)
- {
- if (fIsColor)
- DisposePixPat((PixPatHandle)fDataHandle);
- else
- HPurge(fDataHandle);
- fDataHandle = NULL;
- }
- } // TPattern::ReleasePattern
-
- //----------------------------------------------------------------------------------------
- // TPattern::SetPattern:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TPattern::SetPattern(Handle thePattern,
- Boolean redraw)
- {
- this->ReleasePattern();
- fDataHandle = thePattern;
-
- // get the rsrc id for non-color patterns (color pattern handles aren't resource handles)
- if (!fIsColor)
- {
- ResNumber theID;
- ResType theType;
- CStr255 name;
-
- GetResInfo(thePattern, &theID, &theType, name);
- if (ResError() == noErr)
- fRsrcID = theID;
- }
-
- if (redraw)
- this->ForceRedraw();
- } // TPattern::SetPattern
-
- //----------------------------------------------------------------------------------------
- // TPattern::SetPatternRsrcID:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TPattern::SetPatternRsrcID(ResNumber itsRsrcID, Boolean redraw)
- {
- this->ReleasePattern();
-
- fRsrcID = itsRsrcID;
- if (fRsrcID != kNoResource)
- {
- if (fPreferColor && (qNeedsColorQD || HasColorQD()))
- fDataHandle = (Handle)GetPixPat(fRsrcID); // try to get a 'ppat' resource
-
- if (fDataHandle)
- fIsColor = kPreferColor;
- else // try to get a 'PAT ' resource
- {
- fDataHandle = (Handle)GetPattern(fRsrcID);
- if (fDataHandle)
- fIsColor =!kPreferColor; // Either can't or won't
- }
-
- FailNILResource(fDataHandle); // was FailResError();
- }
-
- if (redraw)
- this->ForceRedraw();
- } // TPattern::SetPatternRsrcID
-
-
- //========================================================================================
- // CLASS TPicture
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TPicture, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPicture constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TPicture::TPicture()
- {
- fDataHandle = NULL;
- fRsrcID = kNoResource;
-
- fEventNumber = mPictureHit;
- } // TPicture::TPicture
-
-
- //----------------------------------------------------------------------------------------
- // TPicture::IPicture:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TPicture::IPicture(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID)
- {
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- FailInfo fi;
- Try(fi)
- {
- this->SetPictureRsrcID(itsRsrcID, kDontRedraw);
-
- fi.Success();
- }
- else // Recover
- {
- this->Free();
-
- fi.ReSignal();
- }
-
- this->SetEnable(FALSE); // Default is to not enable hit testing
- } // TPicture::IPicture
-
- //----------------------------------------------------------------------------------------
- // TPicture::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- TObject* TPicture::Clone() // Override
- {
- MAVolatileInit(TPicture*, aClonedPicture, (TPicture *)(Inherited::Clone()));
-
- // don't call aClonedPicture->ReleasePicture() b/c this will release my picture resource
- aClonedPicture->fRsrcID = kNoResource;
- aClonedPicture->fDataHandle = NULL;
-
- if (fDataHandle)
- {
- FailInfo fi;
- Try(fi)
- {
- aClonedPicture->SetPictureRsrcID(fRsrcID, kDontRedraw);
-
- fi.Success();
- }
- else // Recover
- {
- aClonedPicture->Free();
-
- fi.ReSignal();
- }
- }
-
- return aClonedPicture;
- } // TPicture::Clone
-
-
- //----------------------------------------------------------------------------------------
- // TPicture::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- TPicture::~TPicture()
- {
- this->ReleasePicture();
- } // TPicture::Free
-
- //----------------------------------------------------------------------------------------
- // TPicture::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TPicture::GetStandardSignature() // Override
- {
- return kStdPicture;
- } // TPicture::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TPicture::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TPicture::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- ResNumber itsRsrcID = aStream->ReadInteger();
- this->SetPictureRsrcID(itsRsrcID, kDontRedraw);
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- } // TPicture::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TPicture::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TPicture::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- #if qDebugMsg && !qDrag
- if (fRsrcID == kNoResource)
- fprintf(stderr, "Tried to write TPicture with no resource ID.\n");
- #endif
-
- aStream->WriteInteger(fRsrcID);
- } // TPicture::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TPicture::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TPicture::Draw(const VRect& area) // Override
- {
- if (fDataHandle)
- {
- if (IsAResource((Handle)fDataHandle))
- LoadResource((Handle)fDataHandle);
- if (*fDataHandle) // If there's room for the picture…
- {
- SignedByte oldState = HGetState((Handle)fDataHandle);
- HNoPurge((Handle)fDataHandle);
- PenNormal();
- DrawPicture(fDataHandle, &this->ControlQDArea());
- HSetState((Handle)fDataHandle, oldState);
- }
- }
- Inherited::Draw(area);
- } // TPicture::Draw
-
- //----------------------------------------------------------------------------------------
- // TPicture::ReleasePicture:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TPicture::ReleasePicture()
- {
- fRsrcID = kNoResource;
- if (fDataHandle)
- {
- HPurge((Handle)fDataHandle);
- fDataHandle = NULL;
- }
- } // TPicture::ReleasePicture
-
- //----------------------------------------------------------------------------------------
- // TPicture::SetPicture:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TPicture::SetPicture(PicHandle thePicture,
- Boolean redraw)
- {
- this->ReleasePicture();
- fDataHandle = thePicture;
-
- // get the rsrc id
- ResNumber theID;
- ResType theType;
- CStr255 name;
-
- GetResInfo((Handle)thePicture, &theID, &theType, name);
- if (ResError() == noErr)
- fRsrcID = theID;
-
- if (redraw)
- this->ForceRedraw();
- } // TPicture::SetPicture
-
- //----------------------------------------------------------------------------------------
- // TPicture::SetPictureRsrcID:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TPicture::SetPictureRsrcID(ResNumber itsRsrcID, Boolean redraw)
- {
- this->ReleasePicture();
-
- fRsrcID = itsRsrcID;
-
- if (fRsrcID != kNoResource)
- {
- fDataHandle = GetPicture(fRsrcID);
- FailNILResource((Handle)fDataHandle); // was FailResError();
- }
-
- if (redraw)
- this->ForceRedraw();
- } // TPicture::SetPictureRsrcID
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // TPicture::WillDrag
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- Boolean TPicture::WillDrag( const VPoint& localMouse,
- const RgnHandle dragCursorRegion)
- {
- if (Inherited::WillDrag(localMouse, dragCursorRegion))
- return ((fDataHandle != NULL) || (fRsrcID != kNoResource));
- else
- return FALSE;
- } // TPicture::WillDrag
-
- //----------------------------------------------------------------------------------------
- // TPicture::DoAddDragContent
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TPicture::DoAddDragContent()
- {
- TDragItem *dragItem = TDragDropSession::fgDragDropSession->AddDragItem(1);
- CFlavorFlags flags;
-
- dragItem->PromiseFlavor('PICT', flags);
- } // TPicture::DoAddDragContent
-
- //----------------------------------------------------------------------------------------
- // TPicture::WillAcceptDrop
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TPicture::WillAcceptDrop(CDragItemIterator& dragItemIterator)
- {
- if (TDragDropSession::fgDragDropSession->GetItemCount() != 1)
- return FALSE;
-
- TDragItem *firstItem = dragItemIterator.FirstDragItem();
- return firstItem->FlavorExists('PICT');
- } // TPicture::WillAcceptDrop
-
- //----------------------------------------------------------------------------------------
- // TPicture::DoMakeDragDropCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TCommand* TPicture::DoMakeDragDropCommand(CommandNumber itsCommandNumber,
- CDragItemIterator& dragItemIterator)
- {
- TCommand *returnCommand = NULL;
- TCommandHandler *itsContext = this->GetContext(itsCommandNumber);
-
- switch(itsCommandNumber)
- {
- case cDrag:
- {
- TPictureCommand *dragCommand = new TPictureCommand;
- dragCommand->IPictureCommand(kNoResource, NULL, this, itsCommandNumber,
- itsContext, kCanUndo, kCausesChange, itsContext);
- returnCommand = dragCommand;
- }
- break;
-
- case cDrop:
- {
- Handle pictureHandle = NULL;
- TDragItem *firstItem = dragItemIterator.FirstDragItem();
-
- firstItem->FocusOnFlavor('PICT');
- pictureHandle = firstItem->GetDataAsHandle();
-
- TPictureCommand *dropCommand = new TPictureCommand;
- dropCommand->IPictureCommand(kNoResource, (PicHandle)pictureHandle, this,
- itsCommandNumber, itsContext, kCanUndo, kCausesChange, itsContext);
- returnCommand = dropCommand;
- }
- break;
-
- case cDragMove: // doesn't do anything...will cause return value to be NULL
- break;
-
- default:
- returnCommand = Inherited::DoMakeDragDropCommand(itsCommandNumber, dragItemIterator);
- break;
- }
-
- return returnCommand;
- } // TPicture::DoMakeDragDropCommand
-
- //----------------------------------------------------------------------------------------
- // TPicture::DoFulfillPromise
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TPicture::DoFulfillPromise(TDragItem* promisedItem)
- {
- switch(promisedItem->GetFlavorType())
- {
- case 'PICT':
- {
- if (IsAResource((Handle)fDataHandle))
- LoadResource((Handle)fDataHandle);
- FailNIL(fDataHandle);
- FailNIL(*fDataHandle);
-
- MAVolatileInit(SignedByte, savedState, HGetState((Handle)fDataHandle));
-
- FailInfo fi;
- Try(fi)
- {
- HNoPurge((Handle)fDataHandle);
- promisedItem->SetDataFromHandle((Handle)fDataHandle);
- HSetState((Handle)fDataHandle, savedState);
- fi.Success();
- }
- else
- {
- HSetState((Handle)fDataHandle, savedState);
- fi.ReSignal();
- }
- }
- break;
-
- default:
- Inherited::DoFulfillPromise(promisedItem);
- break;
- }
- } // TPicture::DoFulfillPromise
-
- #endif // qDrag
-
- //========================================================================================
- // CLASS TPictureCommand
- //========================================================================================
- #undef Inherited
- #define Inherited TCommand
-
- #pragma segment MADragNonRes
- MA_DEFINE_CLASS_M1(TPictureCommand, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TPictureCommand::TPictureCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TPictureCommand::TPictureCommand()
- : fSavedRsrcID(kNoResource),
- fSavedDataHandle(NULL)
- {
-
- } // TPictureCommand::TPictureCommand
-
- //----------------------------------------------------------------------------------------
- // TPictureCommand::IPictureCommand
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TPictureCommand::IPictureCommand(ResNumber newRsrcID,
- PicHandle newPicHandle,
- TPicture* itsPictureView,
- CommandNumber itsCommandNumber,
- TCommandHandler* itsContext,
- Boolean canUndo,
- Boolean causesChange,
- TObject* objectToNotify)
- {
- fSavedRsrcID = newRsrcID,
- fSavedDataHandle = newPicHandle;
- fPictureView = itsPictureView;
- //fPriority = kPriorityHigh;
-
- this->ICommand(itsCommandNumber, itsContext, canUndo, causesChange, objectToNotify);
- } // TPictureCommand::IPictureCommand
-
- //----------------------------------------------------------------------------------------
- // TPictureCommand::Free
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TPictureCommand::~TPictureCommand()
- {
- if (fSavedDataHandle)
- {
- if (IsAResource((Handle)fSavedDataHandle))
- {
- ReleaseResource((Handle)fSavedDataHandle);
- fSavedDataHandle = NULL;
- }
- else
- fSavedDataHandle = (PicHandle)DisposeIfHandle((Handle)fSavedDataHandle);
- }
- } // TPictureCommand::Free
-
- //----------------------------------------------------------------------------------------
- // TPictureCommand::DoIt
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TPictureCommand::DoIt()
- {
- PicHandle tempDataHandle = NULL;
-
- // prefer saving the resource ID. If the resource ID is not valid, save the data handle
- ResNumber tempResID = fPictureView->fRsrcID;
- if ( tempResID == kNoResource)
- {
- tempDataHandle = fPictureView->fDataHandle;
- fPictureView->fDataHandle = NULL;
- }
-
- // prefer the resource ID over the data handle
- if (fSavedRsrcID != kNoResource)
- fPictureView->SetPictureRsrcID(fSavedRsrcID, kRedraw);
- else
- fPictureView->SetPicture(fSavedDataHandle, kRedraw);
-
- fSavedRsrcID = tempResID;
- fSavedDataHandle = tempDataHandle;
-
- if (fPictureView->IsDrawable())
- {
- VRect area;
- fPictureView->ControlArea(area);
- EraseRect(&fPictureView->ViewToQDRect(area));
- fPictureView->HandleDraw(area);
- }
- } // TPictureCommand::DoIt
-
- //----------------------------------------------------------------------------------------
- // TPictureCommand::UndoIt
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TPictureCommand::UndoIt()
- {
- this->DoIt();
- } // TPictureCommand::UndoIt
-
- //========================================================================================
- // CLASS TDialogTEView
- //========================================================================================
- #undef Inherited
- #define Inherited TTEView
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TDialogTEView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment TEOpen
-
- TDialogTEView::TDialogTEView()
- {
- fEditText = NULL; // We don't own this reference but we don't
- // want an invalid one either
- fScroller = NULL;
- } // TDialogTEView::TDialogTEView
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::IDialogTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment TEOpen
-
- void TDialogTEView::IDialogTEView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHDeterminer,
- SizeDeterminer itsVDeterminer,
- const VRect& itsInset,
- const TextStyle& itsTextStyle,
- short itsJustification,
- Boolean itsStyleType,
- Boolean itsAutoWrap)
-
- {
- MAVolatileInit(TScroller*, aScroller, NULL);
-
- this->ITEView(itsDocument, itsSuperView, itsLocation, itsSize, itsHDeterminer, itsVDeterminer, itsInset, itsTextStyle, itsJustification, itsStyleType, itsAutoWrap);
-
- FailInfo fi;
- Try(fi)
- {
- aScroller = new TScroller;
- aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, gZeroVPt, !kWantHScrollBar, !kWantVScrollBar);
-
- FailInfo innerFi;
- Try(innerFi)
- {
- aScroller->AddSubView(this);
- innerFi.Success();
- }
- else
- {
- aScroller = (TScroller *)FreeIfObject(aScroller);
- innerFi.ReSignal();
- }
-
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
-
- fScroller = aScroller;
-
- TEFeatureFlag(teFOutlineHilite, teBitClear, fHTE);
- } // TDialogTEView::IDialogTEView
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- TObject* TDialogTEView::Clone() // Override
- {
- MAVolatileInit(TDialogTEView*, aClonedDialogTEView, (TDialogTEView *)(Inherited::Clone()));
-
- aClonedDialogTEView->fEditText = NULL; // no current edittext
- aClonedDialogTEView->fScroller = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- if (this->fScroller)
- {
- // Remove ourselves from the superviews subview list to prevent an
- // infinite recursion.
- this->fScroller->DeleteSubView(this);
- aClonedDialogTEView->fScroller = (TScroller *)(this->fScroller->Clone());
- aClonedDialogTEView->fScroller->AddSubView(aClonedDialogTEView);
-
- aClonedDialogTEView->fScroller->InsertSubView(aClonedDialogTEView, TRUE /*last*/);
- this->fScroller->InsertSubView(this, TRUE /*last*/);
-
- }
- fi.Success();
- }
- else
- {
- aClonedDialogTEView = (TDialogTEView*)FreeIfObject(aClonedDialogTEView);
-
- fi.ReSignal();
- }
-
- return aClonedDialogTEView;
- } // TDialogTEView::Clone
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment TEClose
-
- TDialogTEView::~TDialogTEView()
- {
- if (fScroller)
- {
- fScroller->RemoveSubView(this);
- fScroller = (TScroller *)FreeIfObject(fScroller);
- }
- } // TDialogTEView::Free
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TDialogTEView::ReadFields(TStream* aStream) // Override
- {
- MAVolatileInit(TScroller*, aScroller, NULL);
-
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- aScroller = new TScroller;
- aScroller->IScroller(NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeRelSuperView, gZeroVPt, !kWantHScrollBar, !kWantVScrollBar);
- aScroller->AddSubView(this);
- fi.Success();
- }
- else // Recover
- {
- aScroller = (TScroller *)FreeIfObject(aScroller);
- this->Free();
- fi.ReSignal();
- }
- fScroller = aScroller;
-
- TEFeatureFlag(teFOutlineHilite, teBitClear, fHTE);
- } // TDialogTEView::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TDialogTEView::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- } // TDialogTEView::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::InstallEditText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TDialogTEView::InstallEditText(TEditText* theEditText,
- Boolean selectChars)
- {
- if (fEditText)
- {
- fEditText->RemoveSubView(fScroller);
- fEditText = NULL;
- }
-
- if (theEditText)
- {
- fPreferOutline = theEditText->fPreferOutline;
- fControlChars = theEditText->fControlChars;
- fMaxChars = theEditText->fMaxChars;
- fInset = gZeroVRect;
- //Boolean hadPendingUpdate = theEditText->HasPendingUpdate(); // not used
-
- this->SetJustification(theEditText->fJust, kDontRedraw);
- this->ChangeWrap(theEditText->fAutoWrap, kDontRedraw);
-
- TextStyle aTextStyle = theEditText->fTextStyle;
- this->SetOneStyle(0, 0, doAll, aTextStyle, kDontRedraw);
-
- VRect theControlArea;
- theEditText->ControlArea(theControlArea);
-
- if (fAutoWrap)
- {
- fSizeDeterminer[hSel] = sizeSuperView;
- fSizeDeterminer[vSel] = sizeVariable;
- }
- else
- fSizeDeterminer[hSel] = sizeVariable; // Let the width vary with the number
- // of characters
-
- fSuperView->SetFrame(theControlArea, kDontInvalidate);
-
- {
- CStr255 theText;
- theEditText->GetText(theText);
- this->SetText(theText);
- }
- this->AdjustFrame();
-
- // Make the scroller's thinking match the display that the user already sees
- fScroller->fTranslation.h = 0;
- switch (GetActualJustification(fJustification))
- {
- case teFlushDefault:
- case teFlushLeft:
- fScroller->fTranslation.v = 0;
- break;
- case teFlushRight: // Right brain thinkers… left brain thinkers??
- ((TScroller *)fSuperView)->fTranslation.h = fScroller->fMaxTranslation.h;
- break;
- case teCenter:
- fScroller->fTranslation.h = fScroller->fMaxTranslation.h / 2;
- break;
- }
-
- if (selectChars)
- SetSelect(0, SHRT_MAX, fHTE);
- else
- SetSelect(0, 0, fHTE); // Caller will set the selection.
-
- this->BeInScroller(fScroller);
-
- theEditText->AddSubView(fScroller); // my scroller
- this->SynchView(kDontRedraw);
-
- // Make my enable and my scroller's enable match my new superview
- this->SetEnable(theEditText->IsEnabled());
- fScroller->SetEnable(theEditText->IsEnabled());
- }
- #if qDrag
- // on acquisition, clear drag and drop tracking data
- fLastCaretOffset = 0;
- fLastCaretTime = 0L;
- fCaretIsShown = FALSE;
- #endif
-
- fEditText = theEditText;
- } // TDialogTEView::InstallEditText
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::ResignedTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TDialogTEView::ResignedTarget() // Override
- {
- if (this->IsActive())
- {
- // If we're deselecting a field and it's been scrolled, invalidate it
- // so that it is redrawn correctly.
- if (fScroller->fTranslation.v != 0)
- this->ForceRedraw();
- else
- {
- switch (GetActualJustification(fJustification))
- {
- case teFlushDefault:
- case teFlushLeft:
- if (fScroller->fTranslation.h != 0)
- this->ForceRedraw();
- break;
- case teFlushRight:
- if (fScroller->fTranslation.h != fScroller->fMaxTranslation.h)
- this->ForceRedraw();
- break;
- case teCenter:
- if (fScroller->fTranslation.h != (fScroller->fMaxTranslation.h / 2))
- this->ForceRedraw();
- break;
- }
- }
-
- TView::ResignedTarget(); // send mResignedTarget event
-
- if (fEditText)
- fEditText->StopEdit();
- }
- else
- Inherited::ResignedTarget();
- } // TDialogTEView::ResignedTarget
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::TargetValidationFailed:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TDialogTEView::TargetValidationFailed(long reason) // Override
- {
- if (fEditText)
- fEditText->ValidationFailed(reason);
- } // TDialogTEView::TargetValidationFailed
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::WillingToResignTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- long TDialogTEView::WillingToResignTarget() // Override
- {
- long result = 0;
-
- if (fEditText)
- {
- // this->GetContext(cNoCommand)->CommitLastCommand();
- result = fEditText->GetValidationError();
- }
- return result;
- } // TDialogTEView::WillingToResignTarget
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::ComputeFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TDialogTEView::ComputeFrame(VRect& newFrame)// Override
- {
- Inherited::ComputeFrame(newFrame);
-
- if (fAutoWrap)
- switch (fSizeDeterminer[vSel])
- {
- case sizeVariable:
- // TTEView already computed the variable size, bump it up to at least the scroller's
- // size so that the cursor is claimed for the EditText and the user can click anywhere.
- if (!fStyleType)
- newFrame.bottom = newFrame.top + Max(fScroller->fSize.v, newFrame.GetLength(vSel));
- break;
- }
- else
- switch (fSizeDeterminer[hSel])
- {
- case sizeVariable:
- // TTEView already computed the variable size, bump it up to at least the scroller's
- // size so that the cursor is claimed for the EditText and the user can click anywhere.
- if (!fStyleType)
- newFrame.right = newFrame.left + Max(fScroller->fSize.h, newFrame.GetLength(hSel));
- break;
- }
- } // TDialogTEView::ComputeFrame
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::GetEditText:
- //----------------------------------------------------------------------------------------
- #pragma segment TERes
-
- TEditText* TDialogTEView::GetEditText()
- {
- return fEditText;
- }
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::WillDrag:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- Boolean TDialogTEView::WillDrag(const VPoint& localMouse,
- const RgnHandle dragCursorRegion)
- {
- Boolean result;
- MAVolatileInit(Boolean, savedDraggable, this->GetDraggable());
-
- // temporarily set this view's draggable flag to the state of its edit text
- this->SetDraggable(fEditText->GetDraggable());
-
- FailInfo fi;
- Try(fi)
- {
- result = Inherited::WillDrag(localMouse, dragCursorRegion);
- this->SetDraggable(savedDraggable);
- fi.Success();
- }
- else // Recover
- {
- this->SetDraggable(savedDraggable);
- fi.ReSignal();
- }
-
- return result;
- } // TDialogTEView::WillDrag
-
- //----------------------------------------------------------------------------------------
- // TDialogTEView::DoGetDragProxy:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- TView* TDialogTEView::DoGetDragProxy()
- {
- return fEditText; // fEditText will manage the drag
- } // TDialogTEView::DoGetDragProxy
-
- #endif // qDrag
-
- //========================================================================================
- // CLASS TStaticText
- //========================================================================================
- #undef Inherited
- #define Inherited TControl
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TStaticText, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TStaticText constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TStaticText::TStaticText()
- {
- fDataHandle = NULL;
- fStrListID = kNoResource;
- fIndex = 0;
- fJust = teFlushDefault; // Default to system justification
- fAutoWrap = TRUE;
- fEraseFirst = kNoEraseFirst;
-
- fEventNumber = mStaticTextHit;
- } // TStaticText::TStaticText
-
- //----------------------------------------------------------------------------------------
- // TStaticText::IStaticText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TStaticText::IStaticText(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID,
- short itsIndex)
- {
- this->IControl(itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
-
- fStrListID = itsRsrcID;
- fIndex = itsIndex;
-
- if (fStrListID != kNoResource)
- {
- CStr255 aString;
-
- FailInfo fi;
- Try(fi)
- {
- GetIndString(aString, fStrListID, fIndex);
- FailResError();
- fi.Success();
- }
- else // Recover
- {
- this->Free();
- fi.ReSignal();
- }
- this->SetText(aString, kDontRedraw);
- }
- this->SetEnable(FALSE); // Default is to not enable hit testing
- } // TStaticText::IStaticText
-
- //----------------------------------------------------------------------------------------
- // TStaticText::Clone:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- TObject* TStaticText::Clone() // Override
- {
- MAVolatileInit(TStaticText*, aClonedStaticText, (TStaticText *)Inherited::Clone());
- aClonedStaticText->fDataHandle = NULL;
-
- FailInfo fi;
- Try(fi)
- {
- CStringHandle newString = this->fDataHandle;
- if (newString)
- PermHandToHand((Handle &) newString);
- aClonedStaticText->fDataHandle = newString;
- fi.Success();
- }
- else
- {
- aClonedStaticText->Free();
- fi.ReSignal();
- }
-
- return aClonedStaticText;
- } // TStaticText::Clone
-
- //----------------------------------------------------------------------------------------
- // TStaticText::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- TStaticText::~TStaticText()
- {
- this->ReleaseText();
- } // TStaticText::Free
-
- //----------------------------------------------------------------------------------------
- // TStaticText::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TStaticText::GetStandardSignature() // Override
- {
- return kStdStaticText;
- } // TStaticText::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TStaticText::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TStaticText::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- fAutoWrap = aStream->ReadBoolean();
- fEraseFirst = aStream->ReadBoolean();
-
- fJust = aStream->ReadInteger();
-
- CStr255 itsText;
- fStrListID = aStream->ReadInteger();
- fIndex = aStream->ReadInteger();
- if (fStrListID != kNoResource) // retrieve the static text from the resource
- GetIndString(itsText, fStrListID, fIndex);
- this->SetText(itsText, kDontRedraw);
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TStaticText::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TStaticText::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TStaticText::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteBoolean(fAutoWrap);
- aStream->WriteBoolean(fEraseFirst);
-
- aStream->WriteInteger(fJust);
-
- aStream->WriteInteger(fStrListID);
- aStream->WriteInteger(fIndex);
- } // TStaticText::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TStaticText::ChangeWrap:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TStaticText::ChangeWrap(Boolean newAutoWrap,
- Boolean redraw)
- {
- fAutoWrap = newAutoWrap;
- if (redraw)
- this->ForceRedraw();
- } // TStaticText::ChangeWrap
-
- //----------------------------------------------------------------------------------------
- // TStaticText::DoSubstitution:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TStaticText::DoSubstitution(CStr255& theText)
-
- {
- MAReplaceText(theText);
- } // TStaticText::DoSubstitution
-
- //----------------------------------------------------------------------------------------
- // TStaticText::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TStaticText::Draw(const VRect& area) // Override
- {
- if (fDataHandle)
- {
- CStr255 theText;
- this->GetText(theText);
-
- this->DoSubstitution(theText); // Make the substitution if desired
-
- VRect aVRect;
- this->ControlArea(aVRect);
-
- this->ImageText((Ptr)(((long) & theText) + 1), theText.Length(), aVRect, fJust);
- }
- Inherited::Draw(area);
- } // TStaticText::Draw
-
- //----------------------------------------------------------------------------------------
- // TStaticText::GetText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TStaticText::GetText(CStr255& theText)
- {
- if (fDataHandle)
- CopyStr255((**((String255Handle)fDataHandle)), (Ptr)&theText);
- else
- theText.Empty();
- } // TStaticText::GetText
-
- //----------------------------------------------------------------------------------------
- // TStaticText::ImageText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TStaticText::ImageText(Ptr text,
- long Length,
- const VRect& box,
- short just)
- {
- MATextBox(text, Length, this->ViewToQDRect(box), just, fAutoWrap, NULL, fEraseFirst,
- kSpaceForCaret, fPreferOutline);
- } // TStaticText::ImageText
-
- //----------------------------------------------------------------------------------------
- // TStaticText::ReleaseText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TStaticText::ReleaseText()
- {
- fDataHandle = (CStringHandle)DisposeIfHandle((Handle)fDataHandle);
- } // TStaticText::ReleaseText
-
- //----------------------------------------------------------------------------------------
- // TStaticText::SetJustification:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TStaticText::SetJustification(short theJust,
- Boolean redraw)
- {
- fJust = theJust;
- if (redraw)
- this->ForceRedraw();
- } // TStaticText::SetJustification
-
- //----------------------------------------------------------------------------------------
- // TStaticText::SetText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TStaticText::SetText(const CStr255& theText,
- Boolean redrawImmediately)
- {
- if (!fDataHandle || (theText != **(CStr255**)fDataHandle))
- {
- this->ReleaseText();
- fDataHandle = (CStringHandle)NewString(theText);
- if (MemError() != noErr)
- fDataHandle = NULL;
-
- if (this->IsDrawable())
- {
- this->InvalidateRect(this->ControlQDArea());
-
- if (redrawImmediately)
- this->Update();
- }
- }
- } // TStaticText::SetText
-
- //----------------------------------------------------------------------------------------
- // TStaticText::SetTextWithStrListID:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TStaticText::SetTextWithStrListID(ResNumber theStrListID, short theIndex, Boolean redraw)
- {
- this->ReleaseText();
-
- fStrListID = theStrListID;
- fIndex = theIndex;
- if (fStrListID != kNoResource)
- {
- CStr255 aString;
-
- GetIndString(aString, fStrListID, fIndex);
- FailResError();
- this->SetText(aString, kDontRedraw);
- }
-
- if (redraw)
- this->ForceRedraw();
- } // TStaticText::SetTextWithStrListID
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // TStaticText::DoAddDragContent:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TStaticText::DoAddDragContent()
- {
- CStr255 theText;
- TDragItem *dragItem = TDragDropSession::fgDragDropSession->AddDragItem(1);
- CFlavorFlags flags;
-
- this->GetText(theText);
- this->DoSubstitution(theText);
-
- dragItem->AddFlavor('TEXT', flags, (Ptr)(((long)&theText)+1), theText.Length());
- } // TStaticText::DoAddDragContent
-
- #endif // qDrag
-
- //========================================================================================
- // CLASS TEditText
- //========================================================================================
- #undef Inherited
- #define Inherited TStaticText
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TEditText, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TEditText constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TEditText::TEditText()
- {
- fTEView = NULL;
- fMaxChars = 255;
-
- fControlChars = macroAsSetElem(chLeft) | macroAsSetElem(chRight) |
- macroAsSetElem(chUp) | macroAsSetElem(chDown) |
- macroAsSetElem(chBackspace);
- fTextStyle = gSystemStyle;
- this->SetPenSize(CPoint(1,1)); // …and a thin frame
- fWantsToBeTarget = TRUE;
- fEventNumber = mEditTextHit;
-
- fCursorID = iBeamCursor;
- fLetsSubViewsHandleCursor = FALSE;
- } // TEditText::TEditText
-
- //----------------------------------------------------------------------------------------
- // TEditText::IEditText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TEditText::IEditText(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- short itsMaxChars)
- {
- this->IStaticText(itsSuperView, itsLocation, itsSize, sizeFixed, sizeFixed, kNoResource, 0);
-
- FailInfo fi;
- Try(fi)
- {
- this->SetAdornment(kFrame, kDontRedraw);
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
-
- fMaxChars = itsMaxChars;
-
- this->Inset(VPoint(2, 2), kDontRedraw); // Default is a little, teeny inset…
-
- this->SetEnable(TRUE);
- } // TEditText::IEditText
-
- //----------------------------------------------------------------------------------------
- // TEditText::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
-
- TEditText::~TEditText()
- {
- this->RemoveFloatingTEView();
- } // TEditText::Free
-
- //----------------------------------------------------------------------------------------
- // TEditText::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TEditText::GetStandardSignature() // Override
- {
- return kStdEditText;
- } // TEditText::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TEditText::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TEditText::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- fMaxChars = aStream->ReadInteger();
- fControlChars = aStream->ReadLong();
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TEditText::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TEditText::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TEditText::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteInteger(fMaxChars);
- aStream->WriteLong(fControlChars);
- } // TEditText::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TEditText::WriteSubViews:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TEditText::WriteSubViews(TStream* aStream) // Override
- {
- // remove floating TEView, if any
-
- Inherited::WriteSubViews(aStream);
-
- // restore floating TEView, if any
- } // TEditText::WriteSubViews
-
- //----------------------------------------------------------------------------------------
- // TEditText::HandleMouseDown:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- Boolean TEditText::HandleMouseDown(const VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis,
- EMouseDownType mouseDownType) // Override
- {
-
- if (Inherited::HandleMouseDown(theMouse,event,hysteresis, mouseDownType))
- {
- this->HandleEvent(fEventNumber,this,NULL);
- return TRUE;
- }
- else
- return FALSE;
- } // TEditText::HandleMouseDown
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::DoMouseCommand(VPoint& theMouse,
- TToolboxEvent* event,
- CPoint hysteresis)
- {
- if (fTEView)
- fTEView->DoMouseCommand(theMouse, event, hysteresis);
- else
- Inherited::DoMouseCommand(theMouse, event, hysteresis);
- }
-
- //----------------------------------------------------------------------------------------
- // TEditText::BecameWindowTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::BecameWindowTarget() // Override
- {
- if (!fTEView)
- this->InstallFloatingTEView(FALSE);
-
- Inherited::BecameWindowTarget();
- } // TEditText::BecameWindowTarget
-
- //----------------------------------------------------------------------------------------
- // TEditText::BecameTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::BecameTarget() // Override
- {
- if (fTEView)
- gDispatcher->SetTarget(fTEView);
- else
- {
- this->InstallFloatingTEView(FALSE);
- gDispatcher->SetTarget(fTEView);
- }
-
- Inherited::BecameTarget();
- } // TEditText::BecameTarget
-
- //----------------------------------------------------------------------------------------
- // TEditText::SetTargetSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::SetTargetSelection(Boolean redraw) // Override
- {
- this->SetSelection(0, SHRT_MAX, redraw);// Select all characters
- this->MakeVisible();
- } // TEditText::SetTargetSelection
-
-
- //----------------------------------------------------------------------------------------
- // TEditText::ValidationFailed:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TEditText::ValidationFailed(long reason)
- {
- if (reason != kValidValue)
- {
- if (reason != kErrorHandled) // go ahead and post an alert
- {
- FailOSErr(MAInteractWithUser());
- if ((reason < 1) || (reason > kNoOfDefaultReasons))
- reason = kInvalidValue;
-
- CStr255 aString;
- GetIndString(aString, kInvalidValueReasons, (short)reason);//!!! Note casting
- ParamText(aString, gEmptyString, gEmptyString, gEmptyString);
- StdAlert(phInvalidValue);
- }
- if (fDataHandle)
- this->RestartEdit((**((String255Handle)fDataHandle)));// Restart with previous value
- }
- } // TEditText::ValidationFailed
-
- //----------------------------------------------------------------------------------------
- // TEditText::ChangeWrap:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::ChangeWrap(Boolean newAutoWrap,
- Boolean redraw) // Override
- {
- Inherited::ChangeWrap(newAutoWrap, redraw);
- if (fTEView)
- fTEView->ChangeWrap(newAutoWrap, redraw);
- } // TEditText::ChangeWrap
-
- //----------------------------------------------------------------------------------------
- // TEditText::Deselect:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- Boolean TEditText::Deselect()
- {
- // // Commit the last command to prevent undo from applying to the wrong edit text, and
- // // to ensure that all changes are made before validating.
- // if (fTEView)
- // {
- // fTEView->GetContext(cNoCommand)->CommitLastCommand();
- // }
- // ^^^ Previous code replaced with call to DoneTyping in StopEdit ^^^
-
- long validateResult = this->GetValidationError();
- if (validateResult == kValidValue)
- this->StopEdit();
- else
- {
- this->ValidationFailed(validateResult);
- return FALSE;
- }
- return TRUE;
- } // TEditText::Deselect
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoSubstitution:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::DoSubstitution(CStr255& /* theText */)// Override
- {
- // Default action is for editable text items is not to do any substitions
- } // TEditText::DoSubstitution
-
- //----------------------------------------------------------------------------------------
- // TEditText::GetText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::GetText(CStr255& theText) // Override
- {
- if (!fTEView)
- Inherited::GetText(theText);
- else
- {
- Handle theChars = fTEView->ExtractText();
- short numberOfChars = (short)Min(kStr255Len, GetHandleSize(theChars));
- // delete possible trailing half-character
-
- if (numberOfChars && MACharacterByteType(*theChars, numberOfChars - 1, smCurrentScript) == smFirstByte)
- numberOfChars--;
-
- theText.CopyFrom((void*)(*theChars), numberOfChars);
- }
- } // TEditText::GetText
-
- //----------------------------------------------------------------------------------------
- // TEditText::ImageText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::ImageText(Ptr text,
- long Length,
- const VRect& box,
- short just) // Override
- {
- if (Length >= 0)
- MATextBox(text, Length, ViewToQDRect(box), just, fAutoWrap, NULL, fEraseFirst,
- kSpaceForCaret, fPreferOutline);
- } // TEditText::ImageText
-
- //----------------------------------------------------------------------------------------
- // TEditText::InstallFloatingTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::InstallFloatingTEView(Boolean selectChars)
- {
- if (!fTEView)
- {
- TDialogTEView * aFloatingTEView = this->GetTEView();
- if (!aFloatingTEView)
- {
- #if qDebug
- ProgramBreak("###the acquired TEView is NULL.");
- #endif
- }
- aFloatingTEView->InstallEditText(this, selectChars);
- fTEView = aFloatingTEView;
- }
-
- // since the floating TE view handles dim/hilite drawing - these adorners are removed
- if (fDimmed)
- this->DeleteAdorner(gDimAdorner, kDontRedraw);
- if (fHilite)
- this->DeleteAdorner(gHiliteAdorner, kDontRedraw);
- } // TEditText::InstallFloatingTEView
-
- //----------------------------------------------------------------------------------------
- // TEditText::GetTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- TDialogTEView* TEditText::GetTEView()
- {
- return AcquireFloatingTEView(); // Get it from the server
- } // TEditText::GetTEView
-
- //----------------------------------------------------------------------------------------
- // TEditText::ReleaseTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::ReleaseTEView()
- {
- ReleaseFloatingTEView(fTEView); // Return it to the server for reuse
- fTEView = NULL;
- } // TEditText::ReleaseTEView
-
- //----------------------------------------------------------------------------------------
- // TEditText::MakeVisible:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- void TEditText::MakeVisible()
- {
- VRect myExtent(this->GetExtent());
- myExtent.Inset(VPoint(-10, -10));
-
- // Precalculate these since Min is an inline method.
- long hCoord = Min(myExtent.GetLength(hSel), kMaxCoord);
- long vCoord = Min(myExtent.GetLength(vSel), kMaxCoord);
-
- VPoint minToSee(hCoord, vCoord);
-
- this->RevealRect(myExtent, minToSee, kVisible);
- } // TEditText::MakeVisible
-
- //----------------------------------------------------------------------------------------
- // TEditText::RemoveFloatingTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::RemoveFloatingTEView()
- {
- if (fTEView)
- {
- fTEView->InstallEditText(NULL, FALSE);
- this->ReleaseTEView();
- }
-
- // since the floating TE view handles dim/hilite drawing - these adorners were removed
- if (fDimmed)
- this->AddAdorner(gDimAdorner, kAdornLast - 10, kDontRedraw);
- if (fHilite)
- this->AddAdorner(gHiliteAdorner, kAdornLast - 5, kDontRedraw);
- } // TEditText::RemoveFloatingTEView
-
- //----------------------------------------------------------------------------------------
- // TEditText::RestartEdit:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TEditText::RestartEdit(const CStr255& restartText)
- {
- if (fTEView && fTEView->Focus()) // First, attempt to focus the TEView
- {
- ClipRect(gZeroRect); // Prevent TE from mucking up the hilite with
- // a stinking insertion point
-
- fTEView->SetActive(FALSE); // Deactivate the selection
- this->SetText(restartText, kDontRedraw);// Set the text to previous value
- this->SetSelection(0, SHRT_MAX, kDontRedraw);// Select all characters
-
- fTEView->SetActive(TRUE); // Activate the selection
-
- this->InvalidateFocus(); // Make sure we re-focus
- fTEView->ForceRedraw();
- }
- else
- this->SetText(restartText, kDontRedraw);// Just set the text if we can't focus
- } // TEditText::RestartEdit
-
- //----------------------------------------------------------------------------------------
- // TEditText::SetJustification:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TEditText::SetJustification(short theJust,
- Boolean redraw)
- {
- if (fTEView)
- fTEView->SetJustification(theJust, redraw);
- Inherited::SetJustification(theJust, redraw);
- } // TEditText::SetJustification
-
- //----------------------------------------------------------------------------------------
- // TEditText::SetSelection:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::SetSelection(short selStart,
- short selEnd,
- Boolean redraw)
- {
- if (fTEView)
- {
- fTEView->SetSelection(selStart, selEnd, redraw && (fTEView->IsDrawable()) );
- }
- } // TEditText::SetSelection
-
- //----------------------------------------------------------------------------------------
- // TEditText::SetText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TEditText::SetText(const CStr255& theText,
- Boolean redrawImmediately) // Override
- {
- CStr255 localText(theText);
- if (localText.Length() > fMaxChars)
- {
- #if qDebug
- // ProgramBreak("Truncating text to fMaxChars");
- #endif
- localText.Length() = fMaxChars;
- }
-
- if (fTEView)
- {
- CStr255 currentText;
-
- this->GetText(currentText);
- if (currentText != localText)
- {
- // Make sure fDataHandle's text is the same as that in fTEView
- this->ReleaseText();
- fDataHandle = (CStringHandle)NewString(localText);
- if (MemError() != noErr)
- fDataHandle = NULL;
-
- fTEView->SetText(localText);
- fTEView->RecalcText();
- fTEView->SynchView(kDontRedraw);
- if (this->IsDrawable())
- {
- this->InvalidateRect(this->ControlQDArea());
-
- if (redrawImmediately)
- this->Update();
- }
- }
- }
- else
- Inherited::SetText(localText, redrawImmediately);
- } // TEditText::SetText
-
- //----------------------------------------------------------------------------------------
- // TEditText::StartEdit:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TEditText::StartEdit(Boolean selectChars)
- {
- this->BecomeTarget();
- if (selectChars)
- this->SetTargetSelection(kRedraw);
- } // TEditText::StartEdit
-
- //----------------------------------------------------------------------------------------
- // TEditText::StopEdit:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TEditText::StopEdit()
- {
- if (fTEView)
- {
- CStr255 aString;
-
- fTEView->DoneTyping();
-
- fTEView->SetActive(FALSE); // Hides the selection
- this->GetText(aString); // Must get the text before removing
- // the floating TEView
- this->RemoveFloatingTEView();
- this->SetText(aString, kDontRedraw);
- }
- } // TEditText::StopEdit
-
- //----------------------------------------------------------------------------------------
- // TEditText::GetValidationError:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- long TEditText::GetValidationError() // Override
- {
- long validateResult = Inherited::GetValidationError();
-
- if ((validateResult == kValidValue) && fTEView && (fTEView->GetNumberOfChars() > fMaxChars))
- validateResult = kTooManyCharacters;
- return validateResult;
- } // TEditText::GetValidationError
-
- //----------------------------------------------------------------------------------------
- // TEditText::WantsToBeTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- Boolean TEditText::WantsToBeTarget() // Override
- {
- return (fWantsToBeTarget && this->IsEnabled());
- } // TEditText::WantsToBeTarget
-
- //----------------------------------------------------------------------------------------
- // TEditText::IsTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- Boolean TEditText::IsTarget()
- {
- TEventHandler* currentTarget = gDispatcher->GetTarget();
- return (this == currentTarget) || (fTEView && fTEView->IsTarget());
- } // TEditText::IsTarget
-
- //----------------------------------------------------------------------------------------
- // TEditText::GetDefaultCursorRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TEditText::GetDefaultCursorRegion(const VPoint& /* localPoint */ ,
- RgnHandle cursorRegion)
- {
- RectRgn(cursorRegion,&this->ControlQDArea());
- } // TEditText::GetDefaultCursorRegion
-
- #if qDrag
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoMakeDragCursorRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- RgnHandle TEditText::DoMakeDragCursorRegion()
- {
- RgnHandle dragCursorRegion = NULL;
-
- if (fTEView != NULL)
- dragCursorRegion = fTEView->DoMakeDragCursorRegion();
-
- return dragCursorRegion;
- } // TEditText::DoMakeDragCursorRegion
-
- //----------------------------------------------------------------------------------------
- // TEditText::WillDrag:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- Boolean TEditText::WillDrag(const VPoint& theMouse,
- const RgnHandle dragCursorRegion)
- {
- Boolean willDrag;
-
- if (fTEView != NULL)
- {
- Boolean savedDraggable = fTEView->GetDraggable(); // temporarily set the TEView's
- fTEView->SetDraggable(fDraggable); // is draggable member.
- willDrag = fTEView->WillDrag(theMouse, dragCursorRegion);
- fTEView->SetDraggable(savedDraggable);
- }
- else
- willDrag = FALSE;
-
- return willDrag;
- } // TEditText::WillDrag
-
- //----------------------------------------------------------------------------------------
- // TEditText::GetWillDragCursorID:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- short TEditText::GetWillDragCursorID()
- {
- return kNoResource;
- } // TEditText::WillDrag
-
- //----------------------------------------------------------------------------------------
- // TEditText::GetIsDraggingCursorID:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- short TEditText::GetIsDraggingCursorID()
- {
- return kNoResource;
- } // TEditText::WillDrag
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoAddDragContent:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TEditText::DoAddDragContent()
- {
- // will already have a TEView
- fTEView->DoAddDragContent();
- } // TEditText::DoAddDragContent
-
- //----------------------------------------------------------------------------------------
- // TEditText::WillAcceptDrop:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- Boolean TEditText::WillAcceptDrop(CDragItemIterator& dragItemIterator)
- {
- this->InstallFloatingTEView(FALSE);
- return fTEView->WillAcceptDrop(dragItemIterator);
- } // TEditText::WillAcceptDrop
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoDragEnter:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TEditText::DoDragEnter()
- {
- this->InstallFloatingTEView(FALSE); // get a TDialogTEView
- fTEView->Focus();
- fTEView->DoDragEnter();
- } // TEditText::DoDragEnter
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoMakeDropHiliteRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragRes
-
- RgnHandle TEditText::DoMakeDropHiliteRegion()
- {
- RgnHandle dropRegion = NULL;
- // Will be focused on the TEView.
- // Focus on the EditText to create the correct drop hilite
- this->Focus();
- dropRegion = Inherited::DoMakeDropHiliteRegion();
- InsetRgn(dropRegion, 1, 1); // inset by one pixel to compensate for the border
- return dropRegion;
- } // TEditText::DoMakeDropHiliteRegion
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoDragWithin:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TEditText::DoDragWithin(const VPoint& localMouse)
- {
- fTEView->Focus();
- fTEView->DoDragWithin(localMouse);
- } // TEditText::DoDragWithin
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoDragLeave:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TEditText::DoDragLeave()
- {
- fTEView->Focus();
- fTEView->DoDragLeave();
- } // TEditText::DoDragLeave
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoMakeDragDropCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- TCommand* TEditText::DoMakeDragDropCommand( CommandNumber itsCommandNumber,
- CDragItemIterator& dragItemIterator)
- {
- TCommand *returnCommand = NULL;
-
- switch (itsCommandNumber)
- {
- case cDrag:
- {
- TTECommand *dragCommand = new TTECommand;
- dragCommand->ITECommand(this, itsCommandNumber, TRUE);
- returnCommand = dragCommand;
- }
- break;
-
- case cDrop:
- {
- Handle textHandle = NULL;
- TDragItem *dragItem = dragItemIterator.FirstDragItem();
-
- dragItem->FocusOnFlavor('TEXT');
- textHandle = dragItem->GetDataAsHandle();
- FailNIL(textHandle);
-
- TTEDragDropCommand *dropCommand = new TTEDragDropCommand;
- dropCommand->ITEDragDropCommand(this, itsCommandNumber);
- dropCommand->SetNewText(textHandle, NULL);
- dropCommand->SetNewStart(fTEView->GetLastDropCaretOffset());
- returnCommand = dropCommand;
- }
- break;
-
- case cDragMove:
- {
- TTEDragMoveCommand *dragMoveCommand = new TTEDragMoveCommand;
- dragMoveCommand->ITEDragMoveCommand(this, itsCommandNumber, fTEView->GetLastDropCaretOffset());
- returnCommand = dragMoveCommand;
- }
- break;
-
- default:
- returnCommand = Inherited::DoMakeDragDropCommand(itsCommandNumber, dragItemIterator);
- break;
- }
- return returnCommand;
- } // TEditText::DoMakeDragDropCommand
-
- //----------------------------------------------------------------------------------------
- // TEditText::DoFulfillPromise:
- //----------------------------------------------------------------------------------------
- #pragma segment MADragNonRes
-
- void TEditText::DoFulfillPromise(TDragItem* promisedItem)
- {
- fTEView->DoFulfillPromise(promisedItem);
- } // TEditText::DoFulfillPromise
-
- #endif // qDrag
-
- //========================================================================================
- // CLASS TNumberText
- //========================================================================================
- #undef Inherited
- #define Inherited TEditText
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TNumberText, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TNumberText constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TNumberText::TNumberText()
- {
- fMaximum = LONG_MAX;
- fMinimum = 0;
- } // TNumberText::TNumberText
-
- //----------------------------------------------------------------------------------------
- // TNumberText destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TNumberText::~TNumberText()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TNumberText::INumberText:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TNumberText::INumberText(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- long itsValue,
- long itsMinimum,
- long itsMaximum)
- {
- this->IEditText(itsSuperView, itsLocation, itsSize, 255);
- #if qDebugMsg
- if (itsMinimum > itsMaximum)
- fprintf(stderr, "Minimum value specified is greater than maximum for TNumberText.\n");
- #endif
-
- fMinimum = itsMinimum;
- fMaximum = itsMaximum;
-
- this->SetValue(itsValue, kDontRedraw);
- } // TNumberText::INumberText
-
- //----------------------------------------------------------------------------------------
- // TNumberText::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TNumberText::GetStandardSignature() // Override
- {
- return kStdNumberText;
- } // TNumberText::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TNumberText::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TNumberText::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- long initialValue = aStream->ReadLong();
- fMinimum = aStream->ReadLong();
- fMaximum = aStream->ReadLong();
-
- #if qDebugMsg
- if (fMinimum > fMaximum)
- fprintf(stderr, "Minimum value specified is greater than maximum for TNumberText.\n");
- #endif
-
- this->SetValue(initialValue, kDontRedraw);
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TNumberText::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TNumberText::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TNumberText::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
-
- aStream->WriteLong(this->GetValue());
- aStream->WriteLong(fMinimum);
- aStream->WriteLong(fMaximum);
- } // TNumberText::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TNumberText::GetValue:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- long TNumberText::GetValue()
- {
- long theValue = 0;
- CStr255 theString;
-
- this->GetText(theString);
-
- if (!theString.IsEmpty())
- {
- // Note that we do not check that str2dec works at this point:
- // this method makes an assumption that the text has already
- // been validated…
- StringToNum(theString, &theValue);
-
- #if 0
- #if qModelCFM
- theValue = atol((char*) theString);
- #else
- short index = 0;
- decimal decRec;
- short validPrefix = 0;
- str2dec(theString, &index, &decRec, &validPrefix);
- theValue = (long)dec2num(&decRec);
- #endif
- #endif
- }
-
- return theValue;
- } // TNumberText::GetValue
-
- //----------------------------------------------------------------------------------------
- // TNumberText::SetValue:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TNumberText::SetValue(long newValue, Boolean redraw)
- {
- newValue = MinMax(fMinimum, newValue, fMaximum);
-
- CStr255 aString;
- NumToString(newValue, aString);
- this->SetText(aString, redraw);
- } // TNumberText::SetValue
-
- //----------------------------------------------------------------------------------------
- // TNumberText::GetValidationError:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- long TNumberText::GetValidationError() // Override
- {
- // Empty CStrings are not validated; if a value is desired, override this method
-
- CStr255 theString;
- this->GetText(theString);
-
- if (!theString.IsEmpty())
- {
- #if 0
- short itsLength = theString.Length();
- short index = 0;
- decimal decRec;
- short validPrefix = 0;
- str2dec(theString, &index, &decRec, &validPrefix);
- if (validPrefix && (++index > itsLength) && (decRec.exp >= 0))
- {
- double_t extValue;
- #if qModelCFM
- // work around broken dec2num
- extValue = (double_t) atol((char*) theString);
- #else
- extValue = dec2num(&decRec);
- #endif
- #endif
-
- long extValue;
- StringToNum(theString, &extValue);
-
- if (extValue < fMinimum)
- return kValueTooSmall;
- else if (extValue > fMaximum)
- return kValueTooLarge;
- #if 0
- }
- else
- return kNonNumericCharacters;
- #endif
- }
- return kValidValue;
- } // TNumberText::GetValidationError
-
-
- //========================================================================================
- // CLASS TFloatingTEManager
- //========================================================================================
- #undef Inherited
- #define Inherited TObject
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TFloatingTEManager, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TFloatingTEManager constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- TFloatingTEManager::TFloatingTEManager()
- {
- fCache = NULL;
- } // TFloatingTEManager::TFloatingTEManager
-
- //----------------------------------------------------------------------------------------
- // TFloatingTEManager::IFloatingTEManager:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgInit
-
- void TFloatingTEManager::IFloatingTEManager()
- {
- this->IObject();
- }
-
- //----------------------------------------------------------------------------------------
- // TFloatingTEManager::Free:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
- TFloatingTEManager::~TFloatingTEManager()
- {
- if (fCache)
- fCache = (TDialogTEView *)(FreeIfObject(fCache));
- } // TFloatingTEManager::Free
-
- //----------------------------------------------------------------------------------------
- // TFloatingTEManager::AcquireFloatingTE:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- TDialogTEView* TFloatingTEManager::AcquireFloatingTE()
- {
- if (fCache) // Got one in the cache!
- {
- TDialogTEView * result = fCache;
- fCache = NULL; // Cache is now empty
- return result;
- }
- else
- return this->MakeDialogTEView();
- } // TFloatingTEManager::AcquireFloatingTE
-
- //----------------------------------------------------------------------------------------
- // TFloatingTEManager::MakeDialogTEView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- TDialogTEView* TFloatingTEManager::MakeDialogTEView()
- {
- TDialogTEView * aDialogTEView = NULL;
-
- if (gDispatcher)
- aDialogTEView = (TDialogTEView*)(gViewServer->DoCreateViews(NULL, NULL, kDialogTEViewID, gZeroVPt));
- if (aDialogTEView == NULL)
- {
- #if qDebugMsg
- fprintf(stderr, "Message from TFloatingTEManager::MakeDialogTEView. Did you forget to include Dialog.rsrc?\n");
- #endif
- aDialogTEView = new TDialogTEView;
- aDialogTEView->IDialogTEView(NULL, NULL, gZeroVPt, gZeroVPt, sizeRelSuperView, sizeVariable, gZeroVRect, gSystemStyle, teFlushDefault, kWithoutStyle, FALSE);
-
- }
- aDialogTEView->fMinAhead = 1; // Don't _jump_ the view ahead when
- // autoscrolling for scrollselectionintoview
- return aDialogTEView;
- } // TFloatingTEManager::MakeDialogTEView
-
- //----------------------------------------------------------------------------------------
- // TFloatingTEManager::ReleaseFloatingTE:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- void TFloatingTEManager::ReleaseFloatingTE(TDialogTEView* aDialogTEView)
- {
- fCache = (TDialogTEView*)FreeIfObject(fCache);
- fCache = aDialogTEView;
- } // TFloatingTEManager::ReleaseFloatingTE
-
-
- //========================================================================================
- // CLASS TTargetBorderView
- //========================================================================================
- #undef Inherited
- #define Inherited TView
-
- #pragma segment DlgOpen
- MA_DEFINE_CLASS_M1(TTargetBorderView, Inherited);
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView constructor
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- TTargetBorderView::TTargetBorderView()
- {
- fTargetView = kNoIdentifier;
- fActiveHL = hlOff; // Gets turned on when a subview becomes the target
- fInactiveHL = hlOff; // Don't do dim highlighting
- } // TTargetBorderView::TTargetBorderView
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView destructor
- //----------------------------------------------------------------------------------------
- #pragma segment MADestructorRes
-
- TTargetBorderView::~TTargetBorderView()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::ITargetBorderView:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
-
- void TTargetBorderView::ITargetBorderView(TDocument* itsDocument,
- TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- IDType itsTargetView)
- {
- this->IView(itsDocument, itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet);
- fTargetView = itsTargetView;
- } // TTargetBorderView::ITargetBorderView
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::GetStandardSignature:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- IDType TTargetBorderView::GetStandardSignature() // Override
- {
- return kStdTargetBorderView;
- } // TTargetBorderView::GetStandardSignature
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::ReadFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgReadResource
-
- void TTargetBorderView::ReadFields(TStream* aStream) // Override
- {
- Inherited::ReadFields(aStream);
-
- FailInfo fi;
- Try(fi)
- {
- fTargetView = aStream->ReadIDType();
- fi.Success();
- }
- else
- {
- this->Free();
- fi.ReSignal();
- }
- } // TTargetBorderView::ReadFields
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::WriteFields:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgWriteResource
-
- void TTargetBorderView::WriteFields(TStream* aStream) // Override
- {
- Inherited::WriteFields(aStream);
- aStream->WriteIDType(fTargetView);
- } // TTargetBorderView::WriteFields
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::DoEvent:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TTargetBorderView::DoEvent(EventNumber eventNumber,
- TEventHandler* source,
- TEvent* event) // Override
- {
- switch (eventNumber)
- {
- case mBecameTarget:
- if (this->ContainsTarget(source))
- {
- this->InvalidateBorderRegion();
- }
- Inherited::DoEvent(eventNumber, source, event);
- break;
- case mResignedTarget:
- if (this->ContainsTarget(source))
- {
- this->InvalidateBorderRegion();
- }
- Inherited::DoEvent(eventNumber, source, event);
- break;
-
- default:
- Inherited::DoEvent(eventNumber, source, event);
- break;
- }
- } // TTargetBorderView::DoEvent
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::DoMouseCommand:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TTargetBorderView::DoMouseCommand( VPoint& /* theMouse */,
- TToolboxEvent* /* event */,
- CPoint /* hysteresis */)
- {
- TView *targetView = this->FindSubView(fTargetView);
- if (targetView && targetView->IsEnabled() && targetView->WantsToBeTarget())
- targetView->BecomeTarget();
- } // TTargetBorderView::DoMouseCommand
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::ComputeBorderRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TTargetBorderView::ComputeBorderRegion(RgnHandle borderRegion)
- {
- CRect QDArea(this->GetQDExtent());
- RectRgn(borderRegion, &QDArea);
- QDArea.Inset(CPoint(2, 2));
-
- CTemporaryRegion innerRegion;
- RectRgn(innerRegion, &QDArea );
- DiffRgn(borderRegion, innerRegion, borderRegion);
- } // TTargetBorderView::ComputeBorderRegion
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::InvalidateBorderRegion:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TTargetBorderView::InvalidateBorderRegion()
- {
- CTemporaryRegion borderRegion;
-
- this->ComputeBorderRegion(borderRegion);
- this->InvalidateRegion(borderRegion);
- } // TTargetBorderView::InvalidateBorderRegion
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::Draw:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
-
- void TTargetBorderView::Draw(const VRect& /*area*/)
- {
- if (this->ContainsTarget(gDispatcher->GetTarget()))
- {
- CTemporaryRegion borderRegion;
-
- this->ComputeBorderRegion(borderRegion);
- PaintRgn(borderRegion);
- }
- } // TTargetBorderView::Draw
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::SetFrame:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- void TTargetBorderView::SetFrame(const VRect& newFrame, Boolean invalidate)
- {
- // make sure the entire old frame is invalidated
- if (invalidate)
- this->InvalidateBorderRegion();
-
- Inherited::SetFrame(newFrame, invalidate);
-
- // make sure the entire new frame is invalidated
- if (invalidate)
- this->InvalidateBorderRegion();
- } // TTargetBorderView::SetFrame
-
- //----------------------------------------------------------------------------------------
- // TTargetBorderView::ContainsTarget:
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
-
- Boolean TTargetBorderView::ContainsTarget(TEventHandler *target)
- {
- TEventHandler *localTarget = target;
- Boolean containsTarget = FALSE;
-
- while (localTarget && !containsTarget)
- {
- if (localTarget == this)
- containsTarget = TRUE;
- localTarget = localTarget->GetNextHandler();
- }
- return containsTarget;
- } // TTargetBorderView::ContainsTarget
-
- //----------------------------------------------------------------------------------------
- // End of UDialog.cp
-
- #pragma segment Inline
-